using FSM.IDal; 
using FSM.IBll; 
using FSM.Model; 
using SqlSugar; 
using System; 
using System.Collections.Generic; 
using System.Text; 
 
namespace FSM.Bll 
{ 
    public class SysParamBll: ISysParamBll 
    { 
        #region 模块 
        private readonly ISysParamDal dal; 
        public SysParamBll(ISysParamDal dal) 
        { 
            this.dal = dal; 
        } 
        #endregion 
 
        #region 查询 
 
        /// <summary> 
        /// 根据键值查询单个信息 
        /// </summary> 
        /// <param name="param_no">键值</param> 
        /// <returns></returns> 
        public sys_param Get(int? param_no) 
        { 
            return dal.GetById(param_no); 
        } 
 
        /// <summary> 
        /// 分页查询批量信息 
        /// </summary> 
        /// <param name="param_name"></param> 
        /// <param name="param_desc"></param> 
        /// <param name="page">页码</param> 
        /// <param name="page_size">每页显示的条数</param> 
        /// <returns></returns> 
        public Tuple<List<sys_param>, int> ListPagin(string param_name, string param_desc, int page, int page_size) 
        { 
            ISugarQueryable<sys_param> queryable = dal.CreateQueryable(); 
            queryable = queryable.WhereIF(!string.IsNullOrEmpty(param_name),p => p.param_name == param_name); 
            queryable = queryable.WhereIF(!string.IsNullOrEmpty(param_desc),p => p.param_desc == param_desc); 
             
            PageModel pm = new PageModel 
            { 
                PageIndex = page, 
                PageSize = page_size 
            }; 
            Tuple<List<sys_param>, int> result = dal.GetPageListAndTotal(queryable, pm); 
            return result; 
        } 
 
        /// <summary> 
        /// 分页查询批量信息 
        /// </summary> 
        /// <param name="param_name"></param> 
        /// <param name="param_desc"></param> 
        /// <returns></returns> 
        public List<sys_param> List(string param_name, string param_desc) 
        { 
            Expressionable<sys_param> queryable = Expressionable.Create<sys_param>(); 
            queryable = queryable.AndIF(!string.IsNullOrEmpty(param_name),p => p.param_name == param_name); 
            queryable = queryable.AndIF(!string.IsNullOrEmpty(param_desc),p => p.param_desc == param_desc); 
             
            List<sys_param> result = dal.GetList(queryable.ToExpression()); 
            return result; 
        } 
 
        #endregion 
 
        #region 提交 
 
        /// <summary> 
        /// 添加 
        /// </summary> 
        /// <param name="model">实体</param> 
        /// <returns></returns> 
        public bool Insert(sys_param model) 
        { 
            model.create_date = DateTime.Now;
            model.param_no = dal.GetNewID();
            return dal.Insert(model); 
        } 
 
        /// <summary> 
        /// 更新 
        /// </summary> 
        /// <param name="model">实体</param> 
        /// <returns></returns> 
        public bool Update(sys_param model) 
        { 
            model.edit_date = DateTime.Now; 
            return dal.UpdateExcludeColumns(model, "creater", "create_date") == 1; 
        } 
 
        /// <summary> 
        ///  删除 
        /// </summary> 
        /// <param name="param_no">键值</param> 
        /// <returns></returns> 
        public bool Delete(params int[] param_no_arr) 
        { 
            return dal.Delete(param_no_arr); 
        } 
        #endregion 
    } 
} 
